package com.aahackathon.tripme;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.aahackathon.tripme.model.Trip;

import java.util.ArrayList;

/**
 * Created by Renats on 10/24/2014.
 */
public class TripAdapter extends ArrayAdapter<Trip> {

    private Activity mActivity;

    public TripAdapter(Activity activity, ArrayList<Trip> trips) {
        super(activity, 0, trips);
        mActivity = activity;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null)
            convertView = mActivity.getLayoutInflater()
                    .inflate(R.layout.list_item_trip, null);

        Trip f = getItem(position);

        TextView flightNumber = (TextView) convertView.findViewById(R.id.list_item_trip_flight_number);
        TextView od = (TextView) convertView.findViewById(R.id.list_item_trip_od);

        flightNumber.setText(f.getFlightNumber());
        od.setText(f.getOrigin() + ">" + f.getmDestination());

        return convertView;
    }
}
